Download the Declaration of Independance. There are many sources, I just used https://www.archives.gov/founding-docs/declaration-transcript. Save it as a text file, declaration.txt.
from wordcloud import WordCloud, STOPWORDS
import matplotlib.pyplot as plt
text_file = open('declaration.txt', 'r')
text = text_file.readlines()
wordcloud = WordCloud(
width = 640,
height = 480,
background_color = 'black',
stopwords = STOPWORDS).generate(str(text))
plt.figure(
figsize = (40, 30),
facecolor = 'k',
edgecolor = 'k')
plt.imshow(wordcloud, interpolation = 'bilinear')
plt.axis('off')
plt.tight_layout(pad=0)
plt.show()
Search for an image you want to use, I found a JPG of CONUS with a black foreground & white background. Saved it as USA_Outline.jpg.
import numpy as np
from PIL import Image
usa_mask = np.array(Image.open( 'USA_Outline.jpg'))
wordcloud2 = WordCloud(mask=usa_mask).generate(str(text))
plt.figure(
figsize = (40, 30),
facecolor = 'k',
edgecolor = 'k')
plt.imshow(wordcloud2, interpolation="bilinear")
plt.axis("off")
plt.margins(x=0, y=0)
plt.show()